<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<style>
    .box {
        width: 800px;
        height: 400px;
        margin: 100px auto;
        background-color: pink;

        text-align: center;
    }

    p {
        padding-top: 30px;
        color: red;
        font-size: 30px;
        font-weight: 800;
    }

    .box .question {
        padding-top: 100px;
        padding-bottom: 100px;
        font-size: 20px;
    }
</style>

<body>


<div class="box">
    <p>随机问答</p>
    <div class="question">你想吃冰淇凌嘛?</div>

    <div>
        <button class="start">开始</button>
        <button class="end">结束</button>
    </div>
</div>


<script>
    const questionList = ['大姚帅还是黄涛帅?', '明天有雨嘛?', '人生的意义是什么', '努力真有的汇报嘛?', '你相信命运嘛?', '如何才能更加快乐?']
    const element = document.querySelector('.box .question')
    const startBtn = document.querySelector('.start');
    const endBtn = document.querySelector('.end');


    let interval
    let index
    startBtn.addEventListener('click', function () {
        if (questionList.length === 0) {
            alert('游戏结束,点击刷新再来一次')
        } else {
            interval = setInterval(function () {
                index = Math.floor(Math.random() * questionList.length)
                element.innerHTML = questionList[index]
            }, 100)
        }
    })

    endBtn.addEventListener('click', function () {
            questionList.splice(index, 1)
            clearInterval(interval)
        }
    )
</script>
</body>
</html>